package de.fzi.kasma.learner.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;

public class ILPSettingsTab{

	static String [] ListData = {"http://www.movie.org/ontology.owl#like", 
										 "http://www.movie.org/ontology.owl#dislike"};
	public Text text1;
	public TabItem tab;
	public StartGui startGUI;
	public Combo combo2;
	public Combo combo3;
	
	public ILPSettingsTab(StartGui startGui, final TabFolder parent, int style) {

		
		tab = new TabItem(parent, style);   
		tab.setText ("ILP Settings");

		
		//the group for all combos in the tab 2
	    
		Group ilpGroup = new Group (parent, SWT.CENTER);
		GridLayout gridLayout = new GridLayout ();
		ilpGroup.setLayout (gridLayout);
		gridLayout.numColumns = 1;
		ilpGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL));
		
	    GridData data = new GridData(SWT.FILL, SWT.DEFAULT, true, true, 1, 3);
	    data.horizontalAlignment = SWT.CENTER;
	    ilpGroup.setLayoutData(data);
	    
		/* The first parameter */
		Group group1 = new Group(ilpGroup, SWT.CENTER);
		GridLayout gridLayout2 = new GridLayout ();
		group1.setLayout (gridLayout2);
		gridLayout2.numColumns = 2;
		group1.setText ("The graph index directory location");
		group1.setLayoutData(data);
		text1 = new Text(group1, SWT.BORDER);
	    text1.setText("D:/Arbeit/context/diplom/src/index/100users");
        

		Button button1 = new Button(group1, SWT.NORMAL);
		button1.setText("Browse..");
		SelectionListener OpenDialogListener = new SelectionListener() {
			
			@Override
			public void widgetSelected(SelectionEvent e) {
			    FileDialog dlg = new FileDialog(parent.getShell(), SWT.OPEN);

			    dlg.setFilterPath("C:/");

			    String fileName = dlg.open();
			    if (fileName != null) {
			      System.out.println(fileName);
			      text1.setText(fileName);
			    }
				
			}
			
			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				
			}
		};;;
		button1.addSelectionListener(OpenDialogListener );
		



		/* The next parameter */
	    Group group2 = new Group (ilpGroup, SWT.CENTER);
		group2.setLayout (gridLayout);
		group2.setText ("Relation indicating positive examples for dataset");
		combo2 = new Combo (group2, SWT.DROP_DOWN);
		GridData grid = new GridData ();
		combo2.setLayoutData (grid);
		combo2.setItems (ListData);
		combo2.setText(ListData [0]);
		group2.setLayoutData(data);
		
		/* The next parameter */
	    Group group3 = new Group (ilpGroup, SWT.CENTER);
		group3.setLayout (gridLayout);
		group3.setText ("Relation indicating negative examples for dataset");
		combo3 = new Combo (group3, SWT.DROP_DOWN);
		combo3.setLayoutData (grid);
		combo3.setItems (ListData);
		combo3.setText(ListData [1]);
		group3.setLayoutData(data);



		tab.setControl(ilpGroup);
	    
	    
	}

	public String[] getParams() {

      String[] params = new String[3];
      
      params[0] = "rl.index="+text1.getText();
      params[1] = "rl.pos="+combo2.getText();
      params[2] = "rl.neg="+combo3.getText();
      
		return params;
	}

}
